<template>
  <el-container class="container" style="width: 100%">
    <el-main class="main lum-scrollbar">
      <div v-show="emoticonType === 0" class="emoticon">
        <div
          v-for="(item, i) in emoji.symbol"
          :key="i"
          class="emoticon-item symbol"
          @click="clickEmoticon(item)"
        >
          {{ item }}
        </div>
      </div>
      <div v-show="emoticonType === 1" class="emoji-box">
        <div
          v-for="item in userEmoticonsList"
          class="emoji-item"
          @click="clickImageEmoticon(item, 2)"
        >
          <el-image :src="assets(item.imgUrl)" fit="cover" />
        </div>
      </div>
      <div v-show="emoticonType === 2" class="emoji-box">
        <div
          v-for="item in sysEmoticonsList"
          class="emoji-item"
          @click="clickImageEmoticon(item, 3)"
        >
          <el-image :src="assets(item.imgUrl)" fit="cover" />
        </div>
      </div>
    </el-main>
    <el-footer height="40px" class="no-padding footer">
      <!-- 常用图标 -->
      <div class="footer-item" @click="emoticonTypeChange(0)">
        <img
          class="footer-item-icon"
          src="@/assets/images/icon-emoji_20PX@2x.png"
          alt=""
        />
      </div>
      <!-- 收藏图标 -->
      <div class="footer-item" @click="emoticonTypeChange(1)">
        <img
          class="footer-item-icon"
          src="@/assets/images/icon-like_20PX@2x.png"
          alt=""
        />
      </div>
      <!-- vip图标 -->
      <div class="footer-item" @click="emoticonTypeChange(2)">
        <img
          class="footer-item-icon"
          src="@/assets/images/icon-vip_20PX@2x.png"
          alt=""
        />
      </div>
    </el-footer>
  </el-container>
</template>

<script>
import { emojiList as emoji } from "@/utils/emojis";
import { mapState } from "vuex";
import { inject } from "vue";
import { ipcApiRoute } from "@/api/ipc-route.js";
import { assets } from "@/utils/asset";

export default {
  name: "MeEditorEmoticon",
  computed: {
    ...mapState({
      sysEmoticonsList: (state) => state.emoticon.sysEmoticonsList,
      userEmoticonsList: (state) => state.emoticon.userEmoticonsList,
      currentGroupInfo: (state) => state.chat.currentGroupInfo,
      groupMsgMap: (state) => state.chat.groupMsgMap,
    }),
    showItems() {
      let start = (this.page - 1) * this.pageSize;
      let end = start + this.pageSize;
      return this.emojiItem.slice(start, end);
    },
    pageTotal() {
      return this.emojiItem.length / this.pageSize;
    },
  },
  data() {
    return {
      emoticonType: 0,
      emoji,
      emojiItem: [],

      showEmoticonId: -1,
      showTitle: "QQ表情/符号表情",

      page: 1,
      pageSize: 13,
    };
  },
  props: {
    sessionInfo: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  async created() {
    this.$store.dispatch("FETCH_EMOTICON_LIST", "sys");
    this.$store.dispatch("FETCH_EMOTICON_LIST", "user");
  },
  mounted() {
    this.$ipcInvoke = inject("$ipcInvoke");
  },
  methods: {
    assets,
    emoticonTypeChange(v) {
      this.emoticonType = v;
    },
    // 表情包导航翻页
    turnPage(type) {
      if (type == 1) {
        if (this.page == 1) return false;
        this.page--;
      } else {
        if (this.page >= this.pageTotal) return false;
        this.page++;
      }
    },

    // 点击表情包导航
    triggerItem(item) {
      this.showEmoticonId = item.emoticon_id;
      this.showTitle = item.name;
    },

    // 选中表情
    clickEmoticon(emoji) {
      this.callback({
        type: 1,
        value: emoji,
      });
    },

    // 发送图片表情包
    clickImageEmoticon(item, type) {
      const params = {
        msgSendType: this.sessionInfo.type === 1 ? "PRIVATE" : "GROUP",
        targetId: this.sessionInfo.targetId,
        text: "",
        filePath: JSON.parse(JSON.stringify(item)),
        msgType: "QX:Emoticon",
        atTos: [""],
      };
      this.callback({
        type,
        msg: params,
      });
    },

    callback(type) {
      this.$emit("selected", type);
    },

    // 自定义上传表情
    // customUploadEmoji(e) {
    //   console.log('-------------------------======e', e)
    //   if (e.target.files.length == 0) {
    //     return false;
    //   }

    //   this.$store.commit("UPLOAD_USER_EMOTICON", {
    //     file: e.target.files[0],
    //   });
    // },
  },
};
</script>
<style lang="less" scoped>
.container {
  margin-left: 0;
  height: 274px;
  background-color: white;

  .header {
    line-height: 30px;
    font-size: 13px;
    font-weight: 400;
    padding-left: 5px;
    user-select: none;
    position: relative;
    border-bottom: 1px solid #fbf5f5;

    .addbtn {
      position: absolute;
      right: 10px;
      top: 1px;
      color: #409eff;
      cursor: pointer;
    }
  }

  .footer {
    height: 50px;
    display: flex;
    background-color: #fff;
    border: 1px solid #eeeeee;
    .footer-item {
      margin-left: 7px;
      margin-top: 10px;
      width: 30px;
      height: 30px;
      text-align: center;
      line-height: 30px;
      border-radius: 4px;
      .footer-item-icon {
        display: inline-block;
        height: 20px;
        vertical-align: middle;
        cursor: pointer;
      }
    }
    .footer-item:hover {
      background: #eeeeee;
    }
    .footer-item.active {
      background: #eeeeee;
    }

    .toolbar-items {
      width: 100%;
      height: 40px;
      line-height: 40px;
      display: flex;
      flex-direction: row;
      align-items: center;

      .toolbar-item {
        height: 30px;
        width: 30px;
        margin: 0 2px;
        background-color: #fff;
        display: inline-block;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;

        img {
          width: 20px;
          height: 20px;
        }

        .title {
          display: none;
          position: absolute;
          top: -25px;
          left: 0px;
          height: 20px;
          line-height: 20px;
          background: #353434;
          color: white;
          min-width: 30px;
          font-size: 10px;
          padding-left: 5px;
          padding-right: 5px;
          border-radius: 2px;
          white-space: pre;
          text-align: center;
        }

        &:hover .title {
          display: block;
        }
      }
    }
  }
}

.container .footer .toolbar-items .prev-page:active i,
.container .footer .toolbar-items .next-page:active i {
  transform: scale(1.2);
}

.emoji-box,
.emoticon {
  width: 100%;
}

.emoticon {
  .title {
    width: 50%;
    height: 25px;
    line-height: 25px;
    color: #ccc;
    font-weight: 400;
    // padding-left: 3px;
    font-size: 12px;
  }

  .emoticon-item {
    width: 24px;
    height: 24px;
    margin: 4px;
    float: left;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;

    &:hover {
      transform: scale(1.3);
    }
  }

  .symbol {
    font-size: 22px;
  }
}

.emoji-box {
  .emoji-item {
    width: 52px;
    height: 52px;
    margin: 6px;
    background-color: #eff1f7;
    float: left;
    cursor: pointer;
    transition: ease-in 0.3s;
  }

  .custom-emoji {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    font-size: 10px;

    i {
      font-size: 30px;
      margin-bottom: 3px;
    }

    &:active {
      color: #409eff;
    }
  }
}

/deep/ .el-image {
  width: 100%;
  height: 100%;
  transition: ease-in 0.3s;
}

.emoji-box .emoji-item:hover .el-image,
.emoji-box .emoji-item:hover {
  border-radius: 10px;
}
.lum-scrollbar {
  margin: 12px 0 12px 8px;
  padding: 0;
}
// .lum-scrollbar::-webkit-scrollbar {
//   width: 4px;
//   height: 15px;
//   border-radius: 10px;
// }

// .lum-scrollbar::-webkit-scrollbar-thumb {
//   background: #d5cfcf;
// }

// .lum-scrollbar::-webkit-scrollbar-track {
//   background: #ededed;
// }
/*滚动条大小*/
.lum-scrollbar::-webkit-scrollbar {
  width: 5px;
  height: 10px;
}
/*正常情况下滑块的样式*/
.lum-scrollbar::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  -webkit-box-shadow: inset1px1px0rgba(0, 0, 0, 0.1);
}
/*鼠标悬浮在该类指向的控件上时滑块的样式*/
.lum-scrollbar:hover::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  -webkit-box-shadow: inset1px1px0rgba(0, 0, 0, 0.1);
}
/*鼠标悬浮在滑块上时滑块的样式*/
.lum-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.4);
  -webkit-box-shadow: inset1px1px0rgba(0, 0, 0, 0.1);
}
/*正常时候的主干部分*/
.lum-scrollbar::-webkit-scrollbar-track {
  border-radius: 10px;
  -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0);
  background-color: white;
}
/*鼠标悬浮在滚动条上的主干部分*/
.lum-scrollbar::-webkit-scrollbar-track:hover {
  -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.4);
  background-color: rgba(0, 0, 0, 0.01);
}
</style>
